//
//  MKTChatLink_LinkStyleCVCell.m
//  MKUITestApp
//
//  Created by 苏尚进 on 2021/7/14.
//  Copyright © 2021 moon. All rights reserved.
//

#import "MKTChatLink_LinkStyleCVCell.h"

@implementation MKTChatLink_LinkStyleCVCell
- (id)initWithFrame:(CGRect)frame{
    if (self=[super initWithFrame:frame]) {
        self.linkButton = [[MKUIFlowLayoutButton alloc] init];
        [self.linkButton setTitleColor:[UIColor colorWithRed:0 green:0.5 blue:1 alpha:1] forState:UIControlStateNormal];
        self.linkButton.titleLabel.numberOfLines = 1;
        [self.linkButton.titleLabel setFont:[UIFont systemFontOfSize:14]];
        self.linkButton.titleLabel.adjustsFontSizeToFitWidth = YES;
        self.linkButton.titleLabel.minimumScaleFactor = 11.0/14.0;
        self.linkButton.contentInsets = MKUIEdgeInsetsMakeSameEdge(2);
        [self.linkButton mk_addClickActionBlock:^(MKTChatLink_LinkStyleCVCell *self) {
            MKTChatLink *modelValue = self.collectionCellModel.modelValue;
            [modelValue handleClick:self];
        } context:self];
        [self.contentView addSubview:self.linkButton];
        //
        self.lineView = [[UIView alloc] init];
        self.lineView.backgroundColor = [UIColor grayColor];
        self.lineView.userInteractionEnabled = NO;
        [self.contentView addSubview:self.lineView];
    }
    return self;
}
- (void)customLayoutSubviews{
    [super customLayoutSubviews];
    CGRect bounds = self.bounds;
    self.linkButton.frame = bounds;
    if(!self.lineView.hidden){
        CGRect f2 = bounds;
        f2.size.height = 20;
        f2.size.width = 1.0/[UIScreen mainScreen].scale;
        MKCGRectAlignMaxXToRect(&f2, bounds);
        MKCGRectAlignMidYToRect(&f2, bounds);
        self.lineView.frame = f2;
    }
}
- (void)customReloadCellModel{
    [super customReloadCellModel];
    MKTChatLink *modelValue = self.collectionCellModel.modelValue;
    [self.linkButton setTitle:modelValue.title forState:UIControlStateNormal];
    self.lineView.hidden = self.collectionCellModel.isLastInAllCellModels;
}
@end
